package com.xqls.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.xqls.biz.PermissionBiz;
import com.xqls.biz.RolePermissionKeyBiz;

@Controller
@RequestMapping("/permissionController")
public class PermissionController {
	@Autowired private PermissionBiz permissionBiz;
	
	@Autowired private RolePermissionKeyBiz rolePermissionBiz;
	
	/**
	 * 获取权限信息
	 * 获取角色权限信息
	 * @return JSON
	 */
	@RequestMapping("/getList")
	@ResponseBody 
	public String getList() {
		Map<String,Object> outMap=new HashMap<String,Object>();	
		outMap.put("permissionList", this.permissionBiz.getPermissionTreeList());
		outMap.put("beanList", this.rolePermissionBiz.getList());
		return JSONObject.toJSONString(outMap);
	}
	
	/**
	 * 根据角色编号，获取权限信息
	 * @param roleId
	 * @return JSON
	 */
	@RequestMapping("/getListByRoleId/{roleId}")
	@ResponseBody
	public String getByRoleIdList(@PathVariable String roleId) {
		List<Map<String,Object>> beanList = this.permissionBiz.getPermissionTreeListByRoleId(roleId);
		return JSONObject.toJSONString(beanList);
	}
}
